package com.base.cn.platform.os.controller.classes.topic.reply;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.service.course.classes.topic.reply.ClassesTopicReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/admin/classes/topic/reply")
public class AdminClassesTopicReplyController extends AdminBaseController {

    @Autowired
    private ClassesTopicReplyService classesTopicReplyService;

    @RequestMapping("/ajaxTopicReplyListPage")
    public String ajaxTopicReplyListPage(Model model,
                                         @RequestBody Map<String, Object> topicReply,
                                         @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        Object keyword = topicReply.remove("keyword");
        topicReply.put("user", Collections.singletonMap("keyWord", keyword));
        if(ObjectUtils.isEmpty(keyword)){
            topicReply.put("rootId",0);
        }
        Map<String, Object> dataMap = classesTopicReplyService.findClassesTopicReplyListPage(topicReply, currentPage,10, true, true, false,true);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/classes/topic/reply/ajax-topic-reply-list");
    }

    /**
     * 更新话题评论状态
     *
     * @param ids    话题评论id
     * @param status 1.正常 2.删除
     * @return 操作结果
     */
    @RequestMapping("/updateReplyStatus")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "更新话题评论状态")
    public Map<String, Object> updateReplyStatus(@RequestParam("ids") String ids,
                                                 @RequestParam("status") Integer status) {
        return classesTopicReplyService.updateClassesTopicReplyStatus(ids, status);
    }


    /**
     * 全部回复弹窗页
     *
     * @param id 参数
     */
    @RequestMapping("/allReply")
    @ResponseBody
    public Map<String, Object> toReplySubReplyAll(@RequestParam("id") BigDecimal id , @RequestParam("setAllLeaft") Boolean setAllLeaft ,@RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage) {
     Map params =  new HashMap();
        params.put("id",id);
       return   classesTopicReplyService.findClassesTopicReplyListPage(params, currentPage, null, true, true, setAllLeaft,true);

    }
}
